package com.suoluo.zenadmin.controllers.admin.hotel;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import net.paoding.rose.web.Invocation;
import net.paoding.rose.web.annotation.Param;
import net.paoding.rose.web.annotation.Path;
import net.paoding.rose.web.annotation.rest.Get;
import net.paoding.rose.web.annotation.rest.Post;

import com.suoluo.zenadmin.common.CommonResp;
import com.suoluo.zenadmin.common.JSONPageData;
import com.suoluo.zenadmin.common.SystemType;
import com.suoluo.zenadmin.controllers.JSONInterceptor.JSON;
import com.suoluo.zenadmin.service.InfoService;
import com.suoluo.zenadmin.service.dest.DestService;
import com.suoluo.zenadmin.service.hotel.HotelService;
import com.suoluo.zenadmin.vo.BaseInfoVO;
import com.suoluo.zenadmin.vo.ImageVO;
import com.suoluo.zenadmin.vo.PageVO;
import com.suoluo.zenadmin.vo.dest.DestFeature2VO;
import com.suoluo.zenadmin.vo.dest.DestFeatureItem2VO;
import com.suoluo.zenadmin.vo.dest.DestVO;
import com.suoluo.zenadmin.vo.hotel.Hotel2VO;
import com.suoluo.zenadmin.vo.hotel.HotelResource2VO;
import com.suoluo.zenadmin.vo.hotel.HotelReviewVO;
import com.suoluo.zenadmin.vo.hotel.HotelServicesCategoryVO;
import com.suoluo.zenadmin.vo.hotel.HotelStyleVO;
@Path("/")
public class HotelController {

	@Resource(name="hotelService")
	private HotelService hotelService;
	
	@Resource(name="destService")
	private DestService destService;
	@Resource(name="infoService")
	private InfoService infoService;
	
	/*********************酒店基础服务***start************************/
	/**
	 * 跳转到酒店服务列表页面
	 */
	@Get("service/category/vlist")
	public String toListServiceCategory()
	{
		return "listHotelServiceCategory";
	}
	@JSON
	@Post("service/category/list")
	public Object listServiceCategory()
	{
		return hotelService.findListHotelServiceCategory();
	}
	@Get("service/category/vsave")
	public String toAddServiceCategory()
	{
		return "addHotelServiceCategory";
	}
	@JSON
	@Post("service/category/save")
	public Object saveServiceCategory(HotelServicesCategoryVO serviceVO)
	{
		hotelService.saveServiceCategory(serviceVO);
		return CommonResp.SUCCESS;
	}
	
	@Get("service/category/vupdate")
	public String toUpdateServiceCategory(Invocation invo)
	{
		int serviceId = Integer.parseInt(invo.getParameter("categoryId"));
		HotelServicesCategoryVO servicePOJO = hotelService.findServiceCategoryById(serviceId);
		invo.addModel("servicePOJO",servicePOJO);
		return "updateHotelServiceCategory";
	}
	@JSON
	@Post("service/category/update")
	public Object updateServiceCategory(HotelServicesCategoryVO serviceVO)
	{
		hotelService.updateHotelServiceCategory(serviceVO);
		return CommonResp.SUCCESS;
	}
	@JSON
	@Post("service/category/delete")
	public Object deleteServiceCategory(HotelServicesCategoryVO serviceVO)
	{
		hotelService.deleteServiceCategory(serviceVO);
		return CommonResp.SUCCESS;
	}
	/*********************酒店基础服务***end************************/
	
	/*********************酒店风格***start************************/
	/**
	 * 跳转到酒店服务列表页面
	 */
	@Get("style/vlist")
	public String toListStyle()
	{
		return "listHotelStyle";
	}
	@JSON
	@Post("style/list")
	public Object listStyle()
	{
		return hotelService.findListHotelStyle();
	}
	@Get("style/vsave")
	public String toAddHotelStyle()
	{
		return "addHotelStyle";
	}
	@JSON
	@Post("style/save")
	public Object saveHotelStyle(HotelStyleVO stylePOJO)
	{
		hotelService.saveHotelStyle(stylePOJO);
		return CommonResp.SUCCESS;
		
	}
	
	@Get("style/vupdate")
	public String toUpdateHotelStyle(Invocation invo,@Param("styleId")int styleId)
	{
		HotelStyleVO stylePOJO = hotelService.findHotelStyleById(styleId);
		invo.addModel("hotelStyle",stylePOJO);
		return "updateHotelStyle";
	}
	@JSON
	@Post("style/update")
	public Object updateHotelStyle(HotelStyleVO stylePOJO)
	{
		hotelService.updateHotelStyle(stylePOJO);
		return CommonResp.SUCCESS;
		
	}
	@JSON
	@Post("style/delete")
	public Object deleteHotelStyle(@Param("styleId")int styleId)
	{
		hotelService.deleteHotelStyle(styleId);
		return CommonResp.SUCCESS;
	}
	/*********************酒店风格***end************************/
	/*********************酒店管理***start************************/
	@Get("vlist")
	public String toListHotel(Invocation invo,@Param("destId")int destId)
	{

		DestVO dest = destService.findSimplestDestById(destId);
		invo.addModel("dest",dest);
		return "listHotel";
	}
	@JSON
	@Post("list")
	public Object listHotel(PageVO page,@Param("destId")int destId)
	{
		//查询总的记录
		List<Hotel2VO> rows = hotelService.findListHotelByDestId(page,destId);
		//查询总记录数
		int total = hotelService.findHotelCountByDestId(destId);
		
		JSONPageData data = new JSONPageData();
		data.setRows(rows);
		data.setTotal(total);
		return data;
	}
	@Get("vsave")
	public String toAddHotel(Invocation invo)
	{
		//获取酒店的基础服务列表
		List<HotelServicesCategoryVO> hotelServiceList = hotelService.findListHotelServiceCategory();
		//获取酒店的风格列表
		List<HotelStyleVO> hotelStyleList = hotelService.findListHotelStyle();
		invo.addModel("hotelServiceList",hotelServiceList);
		invo.addModel("hotelStyleList",hotelStyleList);
		return "addHotel";
	}
	@JSON
	@Post("save")
	public Object saveHotel(Hotel2VO hotelVO)
	{
		hotelService.saveHotel(hotelVO);
		return CommonResp.SUCCESS;
	}
	@Get("vupdate")
	public String toUpdateHotel(Invocation invo,@Param("hotelId")int hotelId)
	{
		Hotel2VO hotel = hotelService.findHotelById(hotelId);
		invo.addModel("hotel",hotel);
		return "updateHotel";
	}
	@JSON
	@Post("update")
	public Object updateHotel(Hotel2VO hotelVO)
	{
		hotelService.updateHotel(hotelVO);
		return CommonResp.SUCCESS;
	}
	@JSON
	@Post("delete")
	public Object deleteHotel(Hotel2VO hotelVO)
	{
		hotelService.deleteHotel(hotelVO);
		return CommonResp.SUCCESS;
	}
	/**
	 * 更新酒店关联的服务信息
	 * @param invo
	 * @param hotelId
	 * @return
	 */
	@SuppressWarnings("rawtypes")
	@Get("hotelservice/vupdate")
	public String toUpdateHotelAndService(Invocation invo,@Param("hotelId")int hotelId)
	{
		List<Map> listHotelService = hotelService.findListHotelAndServices(hotelId);
		invo.addModel("hotelService",listHotelService);
		return "updateHotelService";
	}
	@JSON
	@Post("hotelservice/update")
	public Object updateHotelAndService(Hotel2VO hotelVO)
	{
		hotelService.updateHotelAndService(hotelVO);
		return CommonResp.SUCCESS;
	}
	/**
	 * 更新酒店关联的风格信息
	 * @param invo
	 * @param hotelId
	 * @return
	 */
	@SuppressWarnings("rawtypes")
	@Get("hotelstyle/vupdate")
	public String toUpdateHotelAndStyle(Invocation invo,@Param("hotelId")int hotelId)
	{
		List<Map> listHotelStyle = hotelService.findListHotelAndStyles(hotelId);
		invo.addModel("hotelTagList",listHotelStyle);
		return "updateHotelTag";
	}
	/**
	 * 更新酒店关联的风格信息
	 * @param hotelVO
	 * @return
	 */
	@JSON
	@Post("hotelstyle/update")
	public Object updateHotelAndStyle(Hotel2VO hotelVO)
	{
		hotelService.updateHotelAndStryles(hotelVO);
		return CommonResp.SUCCESS;
	}
	
	/*********************酒店管理***end************************/
	
	
	/*********************HotelResource***start************************/
	@Get("resource/vlist")
	public String toListHotelResrouce(Invocation invo,@Param("destId")int destId,@Param("hotelId")int hotelId)
	{
		DestVO dest = destService.findSimplestDestById(destId);
		invo.addModel("dest",dest);
		Hotel2VO hotel = hotelService.findSimplestHotelById(hotelId);
		invo.addModel("hotel",hotel);
		return "listHotelResource";
	}
	@JSON
	@Post("resource/list")
	public Object listHotelResource(@Param("hotelId")int hotelId)
	{
		return hotelService.findHotelResourcesWithoutContentByHotelId(hotelId);
	}
	@Get("resource/vsave")
	public String toAddHotelResource()
	{
		return "addHotelResource";
	}
	@JSON
	@Post("resource/save")
	public Object saveHotelResource(HotelResource2VO resource)
	{
		hotelService.saveHotelResource(resource);
		return CommonResp.SUCCESS;
	}
	@Get("resource/vupdate")
	public String toUpdateHotelResource(Invocation invo,@Param("resourceId")int resourceId)
	{
		HotelResource2VO resource = hotelService.findHotelResourceById(resourceId);
		invo.addModel("resource",resource);
		return "updateHotelResource";
	}
	@JSON
	@Post("resource/update")
	public Object updateHotelResource(HotelResource2VO resource)
	{
		hotelService.updateHotelResource(resource);
		return CommonResp.SUCCESS;
	}
	@JSON
	@Post("resource/delete")
	public Object deleteHotelResoruce(HotelResource2VO resvo)
	{
		hotelService.deleteHotelResource(resvo);
		
		return CommonResp.SUCCESS;
	}
	/*********************HotelResource***end************************/
	
	/*********************HotelResourceItem***start************************/
	@Get("resource/item/vlist")
	public String toListHotelResourceItem(Invocation invo,@Param("hotelId")int hotelId,@Param("resourceId")int resourceId)
	{
		Hotel2VO hotel = hotelService.findSimplestHotelById(hotelId);
		invo.addModel("hotel",hotel);
		DestVO dest = destService.findSimplestDestById(hotel.getDestId());
		invo.addModel("dest",dest);
		HotelResource2VO resource = hotelService.findHotelResourceById(resourceId);
		invo.addModel("resource",resource);
		
		return "listHotelResourceItem";
	}
	@JSON
	@Post("resource/item/list")
	public Object listHotelResourceItem(HotelResource2VO resource)
	{
		hotelService.findHotelResourceAndItems(resource);
		return resource.getImages();
	}
	@Get("resource/item/vsave")
	public String toAddHotelResourceItem()
	{
		return "addHotelResourceItem";
	}
	@JSON
	@Post("resource/item/save")
	public Object saveHotelResourceItem(HotelResource2VO resource)
	{
		hotelService.saveHotelResourceItem(resource);
		return CommonResp.SUCCESS;
	}
	@JSON
	@Post("resource/item/delete")
	public Object deleteHotelResourceItem(ImageVO image)
	{
		infoService.deleteImage(image);
		return CommonResp.SUCCESS;
	}
	@Get("resource/item/vupdate")
	public String toUpdatImage(Invocation inv,@Param("imageId")int imageId){
		ImageVO image = infoService.findImageById(imageId);
		inv.addModel("image",image);
		return "updateImage";
	}
	@JSON
	@Post("resource/item/update")
	public Object updatImage(ImageVO image){
		infoService.updateImage(image);
		return CommonResp.SUCCESS;
	}
	@JSON
	@Post("resource/image/default")
	public Object updateDefaultImage(@Param("resourceId")int resourceId,@Param("imageId")int imageId){
		hotelService.updateDefaultImage(resourceId,imageId);
		return CommonResp.SUCCESS;
	}
	/*********************HotelResourceItem***end************************/
	
	/*********************HotelReview***start************************/
	@Get("review/vlist")
	public String toListHotelReview(Invocation invo,@Param("hotelId")int hotelId)
	{
		Hotel2VO hotel = hotelService.findSimplestHotelById(hotelId);
		invo.addModel("hotel",hotel);
		DestVO dest = destService.findSimplestDestById(hotel.getDestId());
		invo.addModel("dest",dest);
		return "listHotelReview";
	}
	@JSON
	@Post("review/list")
	public Object listHotelReview(@Param("hotelId")int hotelId)
	{
		return hotelService.findListHotelReview(hotelId);
	}
	@Get("review/vsave")
	public String toAddHotelReview()
	{
		return "addHotelReview";
	}
	@JSON
	@Post("review/save")
	public Object saveHotelReview(HotelReviewVO review)
	{
		hotelService.saveHotelReview(review);
		return CommonResp.SUCCESS;
	}
	@Get("review/vupdate")
	public String toUpdateHotelReview(Invocation invo,@Param("reviewId")int reviewId)
	{
		HotelReviewVO review = hotelService.findHotelReviewById(reviewId);
		invo.addModel("review",review);
		return "updateHotelReview";
	}
	@JSON
	@Post("review/update")
	public Object updateHotelReview(HotelReviewVO review)
	{
		hotelService.updateHotelReview(review);
		return CommonResp.SUCCESS;
	}
	@JSON
	@Post("review/delete")
	public Object deleteHotelReview(@Param("reviewId")int reviewId)
	{
		hotelService.deleteHotelReview(reviewId);
		return CommonResp.SUCCESS;
	}
	@Get("review/record/vlist")
	public String toListHotelReviewRecord(Invocation invo,@Param("reviewId")int reviewId,@Param("hotelId")int hotelId)
	{
		Hotel2VO hotel = hotelService.findSimplestHotelById(hotelId);
		invo.addModel("hotel",hotel);
		DestVO dest = destService.findSimplestDestById(hotel.getDestId());
		invo.addModel("dest",dest);
		invo.addModel("reviewId",reviewId);
		
		return "listHotelReviewRecord";
	}
	@JSON
	@Post("review/record/list")
	public Object listHotelReviewRecord(@Param("reviewId")int reviewId)
	{
		return hotelService.findListHotelReviewRecord(reviewId);
	}
	/*********************HotelReview***end************************/
	/******************简化版酒店的图文信息管理**start**********************/
	@Get("text/vlist")
	public String toListHotelText(Invocation inv,@Param("hotelId")int hotelId){
		//获取酒店信息
		Hotel2VO hotel = hotelService.findSimplestHotelById(hotelId);
		inv.addModel("hotel",hotel);
		//获取酒店归属目的地信息
		DestVO dest = destService.findDestById(hotel.getDestId());
		inv.addModel("dest",dest);
		
		return "listHotelText";
	}
	@JSON
	@Post("text/list")
	public Object findListHotelText(@Param("hotelId")int hotelId){
		List<BaseInfoVO> list = infoService.findBaseInfos(hotelId, SystemType.INFO_HOTEL);
		return list;
	}
	
	@Get("text/vsave")
	public String toAddHotelText(){
		return "addHotelText";
	}
	@JSON
	@Post("text/save")
	public Object saveHotelText(BaseInfoVO info){
		hotelService.saveHotelText(info);
		return CommonResp.SUCCESS;
	}
	@Get("text/vupdate")
	public String toUpdateHotelText(Invocation inv,@Param("infoId")int infoId){
		BaseInfoVO info = infoService.findBaseInfoById(infoId);
		inv.addModel("base",info);
		
		return "updateHotelText";
	}
	@JSON
	@Post("text/update")
	public Object updateHotelText(BaseInfoVO info){
		infoService.updateBaseInfo(info);
		return CommonResp.SUCCESS;
	}
	@JSON
	@Post("text/delete")
	public Object deleteHotelText(BaseInfoVO info){
	
		infoService.deleteBaseInfoById(info.getInfoId());
		return CommonResp.SUCCESS;
	}
	
	
	/******************简化版酒店的图文信息管理**start**********************/
	/**************************目的地特色项图片管理**start*****************************/
	@Get("image/vlist")
	public String toListHotelImages(Invocation inv,@Param("infoId")int infoId,@Param("hotelId")int hotelId) {
		
		//获取酒店信息
		Hotel2VO hotel = hotelService.findSimplestHotelById(hotelId);
		inv.addModel("hotel",hotel);
		//获取酒店归属目的地信息
		DestVO dest = destService.findDestById(hotel.getDestId());
		inv.addModel("dest",dest);
		
		BaseInfoVO info = infoService.findBaseInfoById(infoId);
		inv.addModel("info",info);
		
		return "listHotelImages";
	}
	@JSON
	@Post("image/list")
	public Object showHotelImages(@Param("infoId")int infoId) {
		return infoService.findImages(infoId);
	}
	@Get("image/vsave")
	public String toAddHotelImage() {
		return "addHotelImage";
	}
	@JSON
	@Post("image/save")
	public Object saveHotelImage(BaseInfoVO info) {
		hotelService.saveHotelImage(info);
		return CommonResp.SUCCESS;
	}
	@Get("image/vupdate")
	public String toUpdateHotelImage(Invocation inv,@Param("imageId")int imageId) {
		ImageVO images = infoService.findImageById(imageId);
		inv.addModel("images",images);
		return "updateHotelImage";
	}
	@JSON
	@Post("image/update")
	public Object updateHotelImage(ImageVO image) {
		infoService.updateImage(image);
		return CommonResp.SUCCESS;
	}
	@JSON
	@Post("image/delete")
	public Object deleteHotelImage(ImageVO image) {
		infoService.deleteImage(image);
		return CommonResp.SUCCESS;
	}
	
	/**************************目的地特色项图片管理**end*****************************/
	
}
